#pragma once
#include "common.h"

class ThreadCache
{
public:
    //申请内存
    void* Allocate(size_t size);
    //释放内存
    void Freelocate(void* ptr, size_t size);
    //从中心缓存获取内存
    void* FetchFromCentralCache(size_t index, size_t size);
    //释放内存导致链表过长，回收到central cache
    void ReclaimToCentralCache(FreeList& list, size_t size);
private:
    //线程缓存的自由链表桶数组
    FreeList _freeLists[FREE_LISTS];
};

//TLS thread local storage
//通过__thread修饰的TreadCache指针，在每个线程中都有这样的指针,static修饰避免全局冲突
static __thread  ThreadCache* pTLSThreadCache = nullptr;